package com.web.kdl.dao.flywheelDataAnalysis;

import com.web.kdl.entity.flywheelDataAnalysis.FlywheelAlertAnalysis;
import com.web.kdl.entity.flywheelDataAnalysis.FlywheelDataAnalysis;
import com.web.kdl.entity.flywheelDataAnalysis.FlywheelStatusAnalysis;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
@Repository
public interface FlywheelDataAnalysisDao {

    void insert(List<FlywheelDataAnalysis> list);

    void insertAlert(List<FlywheelAlertAnalysis> listAlert);

    void insertStatus(List<FlywheelStatusAnalysis> listStatus);

    void insertStatusflywheel(@Param("list") List<FlywheelStatusAnalysis> flywheel1Status,
                              @Param("flywheelName") String flywheelName);

    void insertlistflywheel(@Param("list") List<FlywheelDataAnalysis> flywheel1list,
                            @Param("flywheelName") String flywheelName);

    void insertAlertflywheel(@Param("list") List<FlywheelAlertAnalysis> flywheel1list,
                             @Param("flywheelName") String flywheelName);

    List<FlywheelDataAnalysis> getDayTempDataList(@Param("tableName") String tableName);

    @Update("DELETE FROM ${tableName} WHERE DATE(`time`) < CURDATE()")
    void deleteBeforeToday(@Param("tableName") String tableName);


    LocalDateTime getMaxDayDataTime(String dayTable);

    List<FlywheelDataAnalysis> getNearestDataInInterval(@Param("tableName") String tableName,@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);

    @Update("DELETE FROM ${tableName} WHERE DATE(`time`) < CURDATE() LIMIT #{batchSize}")
    Integer deleteBeforeTodayBatch(@Param("tableName") String tableName,@Param("batchSize") int batchSize);
}
